const staffService = require('../service/staff.service')
const { WOKER_IS_ALREADY_EXISTS } = require('../config/error')

// 检查师傅是否已存在
const verfiyWoker = async (ctx, next) => {
  const { mobile_phone } = ctx.request.body
  const result = await staffService.getStaffByPhoneNumber(mobile_phone)
  if (result && result.length > 0) {
    return ctx.app.emit('error', WOKER_IS_ALREADY_EXISTS, ctx)
  }
  await next()
}

module.exports = {
  verfiyWoker
}